from threading import RLock, Thread
from typing import List

# 可重入锁解决死锁问题 - 同一个线程可以多次获得这种锁
list_lock = RLock()


def sum_list(int_list: List[int]) -> int:
    print("等待获取锁...")
    with list_lock:
        print("获取到了锁.")
        if len(int_list) == 0:
            print("结束计算.")
            return 0
        else:
            head, *tail = int_list
            print(f"剩余的列表：{tail}")
            return head + sum_list(tail)


print(sum_list([1, 2, 3, 4, 5, 6]))
